package es.udc.emarketapp.emarket.model.countryFacade.actions;

import java.sql.Connection;

import es.udc.emarketapp.emarket.model.country.dao.SQLCountryDAO;
import es.udc.emarketapp.emarket.model.country.dao.SQLCountryDAOFactory;
import es.udc.fbellas.j2ee.util.exceptions.InternalErrorException;
import es.udc.fbellas.j2ee.util.sql.NonTransactionalPlainAction;

public class FindAllCountriesAction implements NonTransactionalPlainAction {

    private String language;

    public FindAllCountriesAction() {
    }

    public FindAllCountriesAction(String language) {
        this.language = language;
    }

    /**
     *
     * @return An instance of <code>ProductChunkVO</code> objects.
     */
    public Object execute(Connection connection)
            throws InternalErrorException {

        /*
         * Find count+1 products to determine if there exist more products
         * above the specified range.
         */
        SQLCountryDAO countryDAO = SQLCountryDAOFactory.getDAO();

         if (!language.equals("es")) {
            language = "en";
        }

        return countryDAO.findAllCountries(connection, language, 1, 239);

    }
}
